/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package formularios;

/**
 *
 * @author rvv
 */
public class encriptador {
    
    private static String patron_busqueda="eP5ÑjaINm19RChtKMYnvxdbSgJGrsz4XV0ñqZOHyoc8LDl3QBwWfk2E6FipA7T";
    private static String Patron_encripta="RgqcME5wOBñt3WKen2GAfv7TH1sjbPkI4odLaDxmÑV0hQNp6JyCYr8XFziSl9Z";
    
    public static String EncriptarCadena(String cadena)
    {
        int idx;
        String result="";
        for(idx=0;idx<cadena.length();idx++)
        {
            result=result+EncriptarCaracter(cadena.substring(idx,idx+1),cadena.length(),idx);
        }
        return result;
    }
    
    public static String EncriptarCaracter(String caracter, int variable, int a_indice)
    {
        int indice;
        if(patron_busqueda.indexOf(caracter)!=-1)
        {
            indice=(patron_busqueda.indexOf(caracter)+variable+a_indice) % patron_busqueda.length();
            return Patron_encripta.substring(indice,indice+1);
        }
        return caracter;
    }
    
    public static String DesEncriptarCadena(String cadena)
    {
        int idx;
        String result="";
        for(idx=0;idx<cadena.length();idx++)
        {
            result=result+DesEncriptarCaracter(cadena.substring(idx,idx+1),cadena.length(),idx);
        }
        return result;
    }
    
    public static String DesEncriptarCaracter(String caracter, int variable, int a_indice)
    {
        int indice;
        if(Patron_encripta.indexOf(caracter)!=-1)
        {
            if((Patron_encripta.indexOf(caracter)-variable-a_indice)>0)
            {
                indice=(Patron_encripta.indexOf(caracter)-variable-a_indice)%Patron_encripta.length();
            }
            else
            {
                indice= patron_busqueda.length()+((Patron_encripta.indexOf(caracter)-variable-a_indice)%Patron_encripta.length());
            }
            indice = indice % Patron_encripta.length();
            return patron_busqueda.substring(indice, indice+1);
        }
        else
        {
            return caracter;
        }
    }
}
